//
//  TriangleView.m
//  LazyCat
//
//  Created by jike on 16/10/9.
//  Copyright © 2016年 zhanshu. All rights reserved.
//

#import "TriangleView.h"

#define triangleViewWith   12
#define triangleViewHeight 5
@implementation TriangleView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame])
    {
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}
#pragma mark 绘制三角形
- (void)drawRect:(CGRect)rect
{
    // 设置背景色
    [[UIColor whiteColor] set];
    //拿到当前视图准备好的画板
    
    CGContextRef  context = UIGraphicsGetCurrentContext();
    
    //利用path进行绘制三角形
    
    CGContextBeginPath(context);//标记
    
    CGContextMoveToPoint(context,
                         0, triangleViewHeight);//设置起点
    
    CGContextAddLineToPoint(context,
                            triangleViewWith / 2.0 ,  0);
    
    CGContextAddLineToPoint(context,
                            triangleViewWith, triangleViewHeight);
    
    CGContextClosePath(context);//路径结束标志，不写默认封闭
    
    [[UIColor whiteColor] setFill];  //设置填充色
    
    [[UIColor whiteColor] setStroke]; //设置边框颜色
    
    CGContextDrawPath(context,
                      kCGPathFillStroke);//绘制路径path    
}

@end
